/**
 * 添加或者修改页面
 */
var ClassificationInfoDlg = {
    data: {
        name: "",
        parentCode: "",
        level: "",
        logPath: "",
        bgPath: "",
        nameA:"",
        levelA:"",
        parentCodeA:""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit1)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/classification/addItem", function (data) {
            if(data.code==200||data.code=="200"){
                Feng.success("添加成功！");
                window.location.href = window.location.href
                $("#div1").css("display","none");
            }else if(data.code==500||data.code=="500"){
                Feng.error("添加失败！" + data.message)
            }
            // window.location.href = Feng.ctxPath + '/classification'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set("name",data.field.nameA);
        ajax.set("level",data.field.levelA);
        ajax.set("parentCode",data.field.parentCodeA);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/classification'
    });
    //返回按钮
    $("#backupPages").click(function () {
        window.location.href = Feng.ctxPath + '/classification'
    });


    $("#show1").click(function () {
        $("#div1").css("display","");
        $("#div2").css("display","none");
    });
    $("#show2").click(function () {
        $("#div2").css("display","");
        $("#div1").css("display","none");
    });



    $.ajax({
        url: Feng.ctxPath + "/classification/getGoodsClass",
        success: function (data) {
            var html = '<option value="" >' + "请选择" + '</option>';
            // 加载数据
            for (var i = 0; i < data.data.length; i++) {
                html += '<option value="' + data.data[i].brandname + '">'
                    + data.data[i].brandname + '</option>'
            }
            $("#nameB").append(html);
            form.render();
        }
    });


    $.ajax({
        url: Feng.ctxPath + "/classification/getParentName",
        success: function (data) {
            var html = '<option value="" >' + "请选择" + '</option>';
            // 加载数据
            for (var i = 0; i < data.data.length; i++) {
                html += '<option value="' + data.data[i].id + '">'
                    + data.data[i].name + '</option>'
            }
            $("#parentCode").append(html);
            form.render();
        }
    });






    //表单提交事件
    form.on('submit(btnSubmit2)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/classification/addItem", function (data) {
            if(data.code==200||data.code=="200"){
                Feng.success("添加成功！");
                window.location.href = Feng.ctxPath + '/classification'
            }else if(data.code==500||data.code=="500"){
                Feng.error("添加失败！" + data.message)
            }
            // window.location.href = Feng.ctxPath + '/classification'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set("name",data.field.nameB);
        ajax.set("level",data.field.levelB);
        ajax.set("parentCode",data.field.parentCodeB);
        ajax.start();

        return false;
    });

});




/*
function selectMater() {
    var html = '<option value="" >'+"请选择"+'</option>';
    $.ajax({
        url: Feng.ctxPath + "/classification/getParentName",
        success: function (data) {
            // 加载数据
            for (var i = 0; i < data.data.length; i++) {
                html += '<option value="' + data.data[i].id + '">'
                    + data.data[i].name + '</option>'
            }

            $("#parentCode").append(html);
        }
    });
}*/
